package com.xlp.drink;

public abstract class AbstractDrink implements Drink{
    private String name;
    private double price;

    public AbstractDrink(String name, double price){
        checkName(name);
        checkPrice(price);
        this.price = price;
        this.name = name;
    }

    /**
     * 饮料价格
     *
     * @return 价格
     */
    @Override
    public double getPrice() {
        return price;
    }

    /**
     * 饮料名称
     *
     * @return 名称
     */
    @Override
    public String getName() {
        return name;
    }

    protected void checkPrice(double price) {
        if (price < 0)
            throw new IllegalArgumentException("饮料价格必须大于等于0元！");
    }

    protected void checkName(String name) {
        if (name == null || name.trim().isEmpty())
            throw new IllegalArgumentException("饮料名称不能为null或空！");
    }
}
